<?php

class McCube_Notifier_Console
    extends McCube_Notifier_Abstract {

    /** */
    public function render($title, $text, $backtraces=false){
        $color = new McCube_Shell_Color();

        return "\n"
            .$this->_decorator($title)
            ."\n"
            .$this->_decorator($text)."\n"
            .($backtraces ? $this->_buildBacktraces() : '')."\n\n"
        ;
    }

    protected function _buildBacktraces(){
        $color = new McCube_Shell_Color();

        $backtrace = $this->_getLastBacktrace();
        if(!$backtrace) return;

        $echo = '';
        if(isset($backtrace['class']))
            $echo .= $backtrace['class'].$backtrace['type'];

        $echo .= $backtrace['function'];

        $echo = '[ '.$color->colorize($echo, 'green').' ]';
        if(isset($backtrace['file']))
            $echo .= ' '.$backtrace['file'].':'.$backtrace['line'];

        return $echo;
    }

    protected function _decoratorCallback($match){
        $color = new McCube_Shell_Color();

        switch($match[1]){
            case 'value' : return $color->colorize($match[2], 'green');break;
            case 'bundle': return $color->colorize($match[2], 'blue');break;
            case 'error' : return $color->colorize(' '.$match[2].' ', 'red', 'light_gray');break;
            case 'alert' : return $color->colorize(' '.$match[2].' ', 'purple', 'light_gray');break;
            case 'notice': return $color->colorize(' '.$match[2].' ', 'blue', 'light_gray');break;
        }

        print_r($match);
    }
}